package net.xdclass.pay;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.response.AlipayTradePagePayResponse;
import net.xdclass.config.AliPayConfig;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @Classname AliPayService
 * @Description TODO
 * @Date 2022/5/26 18:46
 * @Created by sunhao
 */
@Service
public class AliPayService {
  /**
   * 支付宝支付
   */
  public Boolean AliPay(String outTradeNo, BigDecimal totalAmount,String subject) throws AlipayApiException {
    AlipayClient alipayClient = AliPayConfig.getInstance();
    AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
    request.setNotifyUrl("");
    request.setReturnUrl("");
    JSONObject bizContent = new JSONObject();
    bizContent.put("out_trade_no", outTradeNo);
    bizContent.put("total_amount", totalAmount);
    bizContent.put("subject", subject);
    bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY");
    request.setBizContent(bizContent.toString());
    AlipayTradePagePayResponse response = alipayClient.pageExecute(request);
    System.out.println(response.getOutTradeNo());
    return response.isSuccess();
  }
}
